#ifndef BASEEDITFORM_H
#define BASEEDITFORM_H


#include "AbstractEditFormActions.h"


#include <ItemRoot.h>
#include <D20BaseModel.h>


#include <QAction>
#include <QPointer>
#include <QString>



class BaseEditForm : public AbstractEditFormActions
{
public:

    BaseEditForm(ItemRoot* root, D20BaseModel* model)
    {
        m_root = root;
        m_model = model;

        m_model->setRootItem(m_root.data());
    }

    virtual ItemModel* model() const
    {
        return m_model.data();
    }


    virtual ItemRoot* root() const
    {
        return m_root.data();
    }


protected:

    virtual void initialize(QWidget* self = 0)
    {
        if (!self || m_model.isNull() || m_root.isNull()) return;

        int i = 1;
        foreach (QString name, m_model->groupNames())
        {

            QString text = QString("%1 %2").arg(QObject::tr("Add")).arg(name);
            QAction* action = new QAction(text, self);
            action->setObjectName(QString("action%1").arg(text.replace(" ","_")));
            self->addAction(action);

            if (i > 9) continue;

            action->setShortcut(QKeySequence(QString("Ctrl+%1").arg(i++)));
            action->setToolTip(action->shortcut().toString());
        }

    }




protected:

    QPointer<ItemRoot> m_root;
    QPointer<D20BaseModel> m_model;


};

#endif // BASEEDITFORM_H
